<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta name="generator" content=
  "HTML Tidy for Mac OS X (vers 1 September 2005), see www.w3.org" />
  <meta http-equiv="Content-Type" content=
  "text/html; charset=us-ascii" />

  <title>Annotated Field Injection</title>
</head>

<body>
  <h3>Injecting into Annotated Fields &nbsp;</h3>

  <p>This is where a component has an empty constructor with
  dependencies indicated by a field annotation and provided
  automatically by the container after instantiation.</p>

  <div class="source">
    <pre>
public class Apple {
    @Inject
    private Orange orange;
    @Inject
    private Pear pear;
    @Inject
    private Banana banana;
    // methods
}
</pre>
  </div>

  <h4>Usage</h4>

  <div class="source">
    <pre>
pico = new DefaultPicoContainer(new AnnotatedFieldInjection();
pico.addComponent(Apple.class); 
// etc
Apple apple = pico.getComponent(Apple.class);
</pre>
  </div>

  <p>With an custom annotation instead of PicoContainer's
  @Inject</p>

  <div class="source">
    <pre>
pico = new DefaultPicoContainer(new AnnotatedFieldInjection(MyInjectAnnotaton.class);
pico.addComponent(Apple.class);
// etc
Apple apple = pico.getComponent(Apple.class);
</pre>
  </div>

  <p>Yes that's right, there's no constructor needed. It means that
  for a Unit Test, you cannot simply 'new' the class without some
  magic to populate the dependency fields.</p>

  <p>The component factory for this is a class
  <strong>AnnotatedFieldInjection</strong>. It only handles
  annotation-field injection for components.</p>

  <p>Additionally the default component factory
  <strong>AdaptiveInjection</strong> can also handle field
  annotation types, if the @Inject annotation from PicoContainer's
  code-base is used as the marker for injection.
  <strong>AdaptiveInjection</strong> will also fall through to
  constructor injection if there is no recognized @Inject
  annotation.</p>
</body>
</html>
